/*
 * misc.cpp
 *
 *  Created on: 24 Nov 2010
 *      Author: samuel
 */

#include "../include/algorithm.h"


int max_sequence_sum(const int data[], int size)
{
    int sum = 0, max_sum = 0;

    for (int i = 0; i < size; i++)
    {
        sum += data[i];

        if (sum > max_sum)
        {
            max_sum = sum;
        }
        else if (sum < 0)
        {
            sum = 0;
        }
    }

    return max_sum;
}

int alg_gcd(int a, int b)
{
    while (b)
    {
        int c = a % b;
        a = b;
        b = c;
    }

    return a;
}
